package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.dto.business.BusinessPoolDTO;
import com.qk.dto.business.BusinessQueryDTO;
import com.qk.dto.business.BusinessUpdateDTO;
import com.qk.entity.Business;
import com.qk.management.anno.LogOperation;
import com.qk.management.service.BusinessService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 16778
 * @date 2025/10/14 19:57
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/businesses")
public class BusinessController {

    @Autowired
    private BusinessService businessService;

    @LogOperation
    @PostMapping
    public Result insert(@RequestBody Business business){
        log.info("新增业务");
        businessService.insert(business);
        return Result.success();
    }

    @GetMapping
    public Result page(BusinessQueryDTO dto){
        return Result.success(businessService.selectByPage(dto));
    }

    @LogOperation
    @PutMapping("/assign/{businessId}/{userId}")
    public Result assign(@PathVariable Integer businessId, @PathVariable Integer userId){
        log.info("分配业务");
        businessService.assign(businessId, userId);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("查询业务");
        return Result.success(businessService.getWithTrackRecordByBusinessId(id));
    }

    @LogOperation
    @PutMapping
    public Result update(@RequestBody BusinessUpdateDTO dto){
        log.info("更新业务");
        businessService.updateWithBusinessTrackRecordByBusinessId(dto);
        return Result.success();
    }

    @LogOperation
    @PutMapping("/back/{id}")
    public Result convertBackToFake(@PathVariable Integer id){
        businessService.convertBackToFake(id);
        return Result.success();
    }

    @LogOperation
    @PostMapping("/toCustomer/{id}")
    public Result convertToCustomer(@PathVariable Integer id){
        businessService.convertToCustomer(id);
        return Result.success();
    }

    @GetMapping("/pool")
    public Result pool(BusinessPoolDTO dto){
        return Result.success(businessService.pool(dto));
    }

}
